import apiClient from '@/api/apiClient';

const baseUrl = '/sys-job';
const baseUrls = '/sys-jobs';

// 新增
const createSchedule = (data?: any) => apiClient.post({ url: baseUrl, data });

// 删除
const deleteSchedule = (id: number) => apiClient.delete({ url: `${baseUrl}/${id}` });

// 修改
const updateSchedule = (id?: number, data?: any) =>
  apiClient.put({ url: `${baseUrl}/${id}`, data });

// 查询
const getScheduleList = (data) => apiClient.get({ url: baseUrls, params: data });

// /{id}/pause
const disable = (id: number) => apiClient.patch({ url: `${baseUrl}/${id}/pause` });

const enable = (id: number) => apiClient.patch({ url: `${baseUrl}/${id}/resume` });

// jobId/run
const runOnce = (id: number) => apiClient.post({ url: `${baseUrl}/${id}/run` });

export default {
  getScheduleList,
  createSchedule,
  deleteSchedule,
  updateSchedule,
  disable,
  enable,
  runOnce,
};
